package com.eastcompeace.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.eastcompeace.bean.Article;
import com.eastcompeace.dao.ArticleDao;

@Repository
public class ArticleDaoJdbcTemplateImpl implements ArticleDao {

	@Autowired
	private NamedParameterJdbcTemplate jdbcTemplate;

	@Override
	public Long insertArticle(Article article) {
		String sql = "insert into tb_article(title,summary,user_id,create_time,public_time,update_time,status) "
				+ "values(:title,:summary,:userId,:status)";
		Map<String, Object> param = new HashMap<>();
		param.put("title", article.getTitle());
		param.put("summary", article.getSummary());
		param.put("userId", article.getUserId());
		param.put("status", article.getStatus());
		return (long) jdbcTemplate.update(sql, param);
	}
}